import { ScrollViewCom , ScrollItemData} from "../../../base/scrollViewComTS";
import { itemData } from "../../model/testPanelmodel";
const {ccclass, property} = cc._decorator;

@ccclass
export default class testPanelView extends cc.Component {

    @property(cc.Label)
    titleLabel:cc.Label = null;
    @property(cc.Node)
    addBtn:cc.Node = null;
    @property(cc.Node)
    scrollView:cc.Node = null;

    public svCom:ScrollViewCom = null;

    init()
    {
        this.svCom = this.scrollView.getComponent("scrollViewComTS");
        this.svCom.init({cb_host:this, item_setter:this.item_setter})
    }

    set_scrollView(datas:itemData[])
    {
        let svItemdatas:ScrollItemData[] = [];
        for(let index in datas)
        {
            let svItemdata:ScrollItemData =
            {
                key: "item",
                itemData: datas[index],
            }
            svItemdatas.push(svItemdata);
        }
        this.svCom.set_data(svItemdatas);
    }

    item_setter(item:cc.Node, data:any) : [number, number]
    {
        switch(data.key)
        {
            case "item":
                this.item_RenderFunc1(item, data);
            break;
        }
        return [item.width, item.height];
    }

    item_RenderFunc1(item:cc.Node, data:any)
    {
        let itemData:itemData = data.itemData;
        let nameLabel = item.getChildByName("name").getComponent(cc.Label);
        let value1Label = item.getChildByName("value1").getComponent(cc.Label);
        let value2Label = item.getChildByName("value2").getComponent(cc.Label);
        let value3Label = item.getChildByName("value3").getComponent(cc.Label);

        nameLabel.string = itemData.name;
        value1Label.string = itemData.value1.toString();
        value2Label.string = itemData.value2.toString();
        value3Label.string = itemData.value3.toString();
    }

    clearAll_Item()
    {
        this.svCom.clear_items();
    }

    set_title(title:string)
    {   
        this.titleLabel.string = title;
    }
}
